package com.msu.nava.util;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.msu.nava.modle.Medicine;
import com.msu.nava.modle.Msmapper;
import com.msu.nava.modle.ResultSheet;
import com.msu.nava.modle.SickDetailItem;
import com.msu.nava.modle.ViewObject;

import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class GsonUtil {
    private static Gson gson = new Gson();
    private static OkHttpClient client = new OkHttpClient();
    public static String toJsonString(Object obj) {
        return gson.toJson(obj);
    }

    public static List<SickDetailItem> toSickDetailItems(String jsonString) {
        Type type = new TypeToken<ArrayList<SickDetailItem>>() {
        }.getType();
        List<SickDetailItem> items;
        try {
            items = gson.fromJson(jsonString, type);
            return items;
        }catch (JsonSyntaxException e){
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 转换成VO对象
     * @param jsonString
     * @return
     */
    public static ViewObject toViewObject(String jsonString){
        Type type = new TypeToken<ViewObject>() {
        }.getType();
        ViewObject vo = gson.fromJson(jsonString, type);
        return vo;
    }

    public static ResultSheet getResultSheet(String jsonString){
        Type type = new TypeToken<ResultSheet>() {
        }.getType();
        ResultSheet rs = gson.fromJson(jsonString, type);
        return rs;
    }

}